define(function() {
	return function($compile, $scope) {
		require(
				[ "AppPathDir/register/visitorInfos/visitorSupport",
						"AppPathDir/register/visitorInfos/addSupport",
						"AppPathDir/register/visitorInfos/updateSupport",
						"PDUtilDir/util", "PDUtilDir/tool",
						"PDUtilDir/slidebar", "PDUtilDir/inputSelect", "Date",
						"DateCN", "css!DateCss" ],
				function(Support, AddSupport, UpdateSupport, Util, Tool,
						Slidebar, inputSelect) {
					/* 查询 start */
					$scope.cache = {
						types : new Array(),
						typeMap: new Map(),
						certificates : new Array()
					};
					$scope.search = {
						zhName : "",
						enName : ""
					}
					$scope.searchSupport = {
						run : function() {
							$scope.grid.reload({
								queryParam : {
									zhName : $scope.search.zhName,
									enName : $scope.search.enName
								}
							})
						}
					};
					/* 查询 end */
					$scope.addSupport = AddSupport($scope, $compile);
					$scope.updateSupport = UpdateSupport($scope, $compile);

					$scope.delSupport = {
						run : function() {
							var selectRows = $scope.grid.getSelectedRow();
							if (null != selectRows) {
								Util.confirm("是否要删除", function() {
									var ids = new Array();
									$.each(selectRows, function(index, selectRow) {
										ids.push(selectRow.id);
									});
									$.ajax({
										url : getServer()
												+ "/flea/hclv/visitor/deleteByIds.htmls",
										method : 'post',
										data : {
											'ids' : JSON
													.stringify(ids)
										},
										success : function(
												data) {
											$scope.grid
													.refresh();
											Util
													.alert(data.message);
										}
									});

								});
							} else {
								Util.alert('请选择要删除的数据！');
							}
						}
					};
					$scope.gridRender = function() {
//						if($scope.cache.types.length > 0 && $scope.cache.certificates.length > 0){
							$scope.grid = Support.init($scope.cache, $scope.addSupport,
									$scope.updateSupport, $scope.delSupport,
									$scope.searchSupport);
//						}
					};
					
					var init = function() {
						$.ajax({
							url : getServer() + "/flea/hclv/getCertificates.htmls",
							success : function(data) {
								$scope.cache.certificates = data.data;
								$scope.gridRender();
								// 证件类型
//								inputSelect.dropCache();
//								inputSelect({
//									id : "queryType",
//									key : {
//										id : "dictCode",
//										name : "dictName",
//										data : "data",
//									},
//									data : $scope.cache.certificates,
//									simpleData : true,
//									// 启用文本搜索
//									// initData:[initProvice],
//									searchAble : false,
//									callback : function(id) {
//										$scope.search.type = id[0];
//									}
//								});
							}
						});
						//游客类型
						$.ajax({
							url : getServer() + "/flea/hclv/getVisitorType.htmls",
							success : function(data) {
								$scope.cache.types = data.data;
								$.each(data.data, function(index, row) {
									$scope.cache.typeMap.set(row.dictCode, row.dictName);
								});
								$scope.gridRender();
							}
						});
					}
					init();
					Support.init($scope.cache, $scope.addSupport,
							$scope.updateSupport, $scope.delSupport,
							$scope.searchSupport);
				})
	}
});